﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Infrastructure.Annotations;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Delphi.Mimir.Data.Entities.Final.Mappings {
    
    public class CountryMap : EntityTypeConfiguration<Country> {
        public CountryMap() {
            /******************************************************************
            /* Table
            /*****************************************************************/
            ToTable("fin.com_countries");

            /******************************************************************
            /* Primary Key
            /*****************************************************************/
            HasKey(c => c.CountryId);

            /******************************************************************
            /* Index
            /*****************************************************************/
            // IX_COM_CNT_CD
            Property(c => c.Code)
                .HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute("IX_COM_CNT_CD", 1) { IsUnique = true }));
            Property(c => c.ShortCode)
                .HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute("IX_COM_CNT_CD", 2) { IsUnique = true }));

            /******************************************************************
            /* Relationships
            /*****************************************************************/
            // 0..1:n Currency
            HasOptional<Currency>(c => c.Currency)
                .WithMany()
                .HasForeignKey(c => c.CurrencyId);

            /******************************************************************
            /* Properties
            /*****************************************************************/
            Property(c => c.CountryId)
                .HasColumnName("cnt_id");

            Property(c => c.Code)
                .IsRequired()
                .IsUnicode(false)
                .HasMaxLength(25)
                .HasColumnName("cnt_cd");

            Property(c => c.ShortCode)
                .IsRequired()
                .IsUnicode(false)
                .HasMaxLength(25)
                .HasColumnName("cnt_short_cd");

            Property(c => c.Name)
                .IsRequired()
                .IsUnicode(true)
                .HasMaxLength(250)
                .HasColumnName("cnt_desc");

            Property(c => c.CurrencyId)
               .IsOptional()
               .HasColumnName("cnt_cur_id");

            Property(c => c.NumericCode)
                .IsOptional()
                .HasColumnName("cnt_numeric_cd");

            Property(c => c.CurrencyCountryName)
                .IsOptional()
                .IsUnicode(true)
                .HasMaxLength(250)
                .HasColumnName("cnt_cur_desc");
        }
    }
}
